# -*- coding: utf-8 -*-

from osv import fields,osv
from osv.orm import browse_record
import tools
from functools import partial
import pytz
import pooler
from tools.translate import _
from service import security
import netsvc
import datetime

class aas_current_academic_state(osv.TransientModel):
    _name = 'aas.current.academic.state'
    _columns = {
        'year': fields.many2one('aas.academic.year', string='Năm học'),
        'semester': fields.many2one('aas.academic.semester', string='Học kỳ'),
        'week': fields.many2one('aas.academic.week', string='Tuần học'),
    }
    
    def default_get(self, cr, uid, fields, context=False):
        res = super(aas_current_academic_state, self).default_get(cr, uid, fields, context=context)
        res = {'year': False, 'semester': False, 'week': False}
        year_obj = self.pool.get('aas.academic.year')
        (year, semester, week) = year_obj.get_current_academic_state(cr, uid, context=context)
        if year: res.update({'year': year.id})
        if semester: res.update({'semester': semester.id})
        if week: res.update({'week': week.id})
        return res
    
    def save_current_academic_state(self, cr, uid, ids, context=False):
        obj = self.browse(cr, uid, ids[0], context=context)
        year_obj = self.pool.get('aas.academic.year')
        year_id = obj.year and obj.year.id or -1
        semester_id = obj.semester and obj.semester.id or -1
        week_id = obj.week and obj.week.id or -1
        year_obj.set_current_academic_state(cr, uid, year_id, semester_id, week_id, context=context)
        return {
            'view_type': 'form', 
            'view_mode': 'form', 
            'res_model': 'aas.current.academic.state',
            'type': 'ir.actions.act_window', 
            'target': 'new',
        }
    
aas_current_academic_state()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
